package caiwei.android.activity;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import caiwei.android.R;
import caiwei.android.activity.base.ActivityFrame;

/**
 * 基础知识之二，Activtiy的详细展示LauncherModel的standard的启动Activity
 * 
 * @author caiwei
 * @date2012-3-9
 * @version 1.0
 */
public class ActivityGridBaseActivityFirst extends ActivityFrame implements
		OnClickListener
{
	private static final int RESQUESTCODE = 1234;
	protected Button mSelfButton, mFristToSecondButton, mFristToThirdButton,
			mFristToFourtButton;
	TextView mTextView;
	private String mLogTag = "MyLog";
	String mActivityName, mTextViewText;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		appendMainBody(R.layout.lay_activity_first);
		removeBottomBox();
		initVariable();
		initView();
		Log.i(mLogTag, mActivityName + "onCreate" + "  TaskId:" + getTaskId());
		if ("FirstActivity".equals(mActivityName))
		{
			LinearLayout _LinearLayout = (LinearLayout) findViewById(R.id.layactivityfirst);
			Button _IntentButton = new Button(this);
			_IntentButton.setText(R.string.btnIntentWithPresent);
			Button _CallButton = new Button(this);
			_CallButton.setText(R.string.btnIntentActionCall);
			Button _ActionButton = new Button(this);
			_ActionButton.setText(R.string.btnIntentActionMy);
			Button _ActionSMS = new Button(this);
			_ActionSMS.setText(R.string.btnIntentSMS);
			LayoutParams _LayoutParams = new LayoutParams(
					LinearLayout.LayoutParams.FILL_PARENT,
					LinearLayout.LayoutParams.WRAP_CONTENT);
			_IntentButton.setLayoutParams(_LayoutParams);
			_ActionButton.setLayoutParams(_LayoutParams);
			_CallButton.setLayoutParams(_LayoutParams);
			_ActionSMS.setLayoutParams(_LayoutParams);
			_LinearLayout.addView(_IntentButton);
			_LinearLayout.addView(_CallButton);
			_LinearLayout.addView(_ActionButton);
			_LinearLayout.addView(_ActionSMS);
			_IntentButton.setOnClickListener(new OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					Intent _Intent = new Intent(
							ActivityGridBaseActivityFirst.this,
							ActivityIntentPresent.class);
					_Intent.putExtra("present", "我给你的礼物");
					startActivityForResult(_Intent, RESQUESTCODE);
				}
			});
			_CallButton.setOnClickListener(new OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					Intent _Intent = new Intent();
					_Intent.setAction(Intent.ACTION_CALL);
					_Intent.setData(Uri.parse("tel:13801111513"));
					startActivity(_Intent);
				}
			});
			_ActionButton.setOnClickListener(new OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					Intent _Intent = new Intent();
					_Intent.setAction("myAction");
					startActivity(_Intent);
				}
			});
			_ActionSMS.setOnClickListener(new OnClickListener()
			{

				@Override
				public void onClick(View v)
				{
					Intent _Intent = new Intent();
					_Intent.setAction(Intent.ACTION_SENDTO);
					_Intent.setData(Uri.parse("smsto:13801111513"));
					_Intent.putExtra(android.content.Intent.EXTRA_TEXT, "Text");
					startActivity(_Intent);
				}
			});
		}
	}

	protected void initVariable()
	{
		mActivityName = "FirstActivity";
		mTextViewText = getResources().getString(R.string.FirstActivitywelcome);
	}

	protected void initView()
	{
		mSelfButton = (Button) findViewById(R.id.btnSelf);
		mSelfButton.setOnClickListener(this);
		mFristToSecondButton = (Button) findViewById(R.id.btnFirstToSecondActivity);
		mFristToSecondButton.setOnClickListener(this);
		mFristToThirdButton = (Button) findViewById(R.id.btnFirstToThird);
		mFristToThirdButton.setOnClickListener(this);
		mFristToFourtButton = (Button) findViewById(R.id.btnFirstToFourth);
		mFristToFourtButton.setOnClickListener(this);
		mTextView = (TextView) findViewById(R.id.tvlayactivityWolcome);
		mTextView.setText(mTextViewText);
		mTextView.setTextColor(Color.BLUE);
	}

	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.btnSelf:
			openActivityAnim(ActivityGridBaseActivityFirst.class);
			break;
		case R.id.btnFirstToSecondActivity:
			openActivityAnim(ActivityGridBaseActivitySecond.class);
			break;
		case R.id.btnFirstToThird:
			openActivityAnim(ActivityGridBaseAcitvityThird.class);
			break;
		default:
			openActivityAnim(ActivityGridBaseActivityFourth.class);
			break;
		}
	}

	@Override
	protected void onStart()
	{
		super.onStart();
		Log.i(mLogTag, mActivityName + "onStart");
	}

	@Override
	protected void onResume()
	{
		super.onResume();
		Log.i(mLogTag, mActivityName + "onResume");
	}

	@Override
	protected void onPause()
	{
		super.onPause();
		Log.i(mLogTag, mActivityName + "onPause");
	}

	@Override
	protected void onStop()
	{
		super.onStop();
		Log.i(mLogTag, mActivityName + "Stop");
	}

	@Override
	protected void onDestroy()
	{
		super.onDestroy();
		Log.i(mLogTag, mActivityName + "onDestory");
	}

	@Override
	protected void onRestart()
	{
		super.onRestart();
		Log.i(mLogTag, mActivityName + "onRestart");
	}

	// 接收返回码回调方法
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		// super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == 4321 && data != null)
		{
			String returnValue = data.getStringExtra("back");
			Toast.makeText(this, "返回值：" + returnValue, Toast.LENGTH_LONG)
					.show();
		}
	}
}
